<template>
  <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
    <div class="Logout">
      <Logout>退出</Logout>
    </div>
<!--    <el-button type="danger" @click="Logout">退出登录</el-button>-->
    <h1>添加教师信息</h1>
    <el-form-item label="教师编号" prop="id">
      <el-input style="width: 800px" v-model="ruleForm.id" placeholder="请输入教师编号" prefix-icon="el-icon-s-check" maxlength="10" show-word-limit clearable></el-input>
    </el-form-item>
    <el-form-item label="教师姓名" prop="name">
      <el-input style="width: 800px" v-model="ruleForm.name" placeholder="请输入教师名称" prefix-icon="el-icon-user-solid" maxlength="50" show-word-limit clearable></el-input>
    </el-form-item>
    <el-form-item label="教师等级" prop="level">
<!--      <el-input v-model="ruleForm.level"></el-input>-->
      <el-select v-model="ruleForm.level" placeholder="请选择教师等级">
        <el-option label="1" value="1"></el-option>
        <el-option label="2" value="2"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="教师特征" prop="type">
      <el-input style="width: 800px" v-model="ruleForm.type" placeholder="请输入教师特长" prefix-icon="el-icon-s-management" maxlength="50" show-word-limit clearable></el-input>
    </el-form-item>

    <el-form-item>
      <el-button type="success" @click="submitForm('ruleForm')" icon="el-icon-check">提交</el-button>
      <el-button type="danger" @click="resetForm('ruleForm')" icon="el-icon-refresh">重置</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import Logout from "./Logout";
export default {
  name: "AddTeacher",
  components: {Logout},
  data () {
    return {
      ruleForm: {
        id: '',
        name: '',
        level: '',
        type: '',
      },
      rules: {
        id:
          {required: true, message: '请输入教师编号', trigger: 'blur'},

        name:
          {required: true, message: '请输入教师姓名', trigger: 'blur'},

        level:
          {required: true, message: '请输入教师等级', trigger: 'change'},

        type:
          {required: true, message: '请输入教师特长', trigger: 'blur'}

      },
    }
  },
  methods : {
    submitForm(formName) {
      const _this=this
      this.$refs[formName].validate((valid) => {
        if (valid) {
          console.log(_this.ruleForm)
          //这个地方进行axios提交后台信息
          const params = {
            tno:_this.ruleForm.id,
            tname:_this.ruleForm.name,
            tlevel:_this.ruleForm.level,
            tcharacter:_this.ruleForm.type,

          }
          console.log("tno:", params.tno, " tname:", params.tname, " tlevel:", params.tlever, " tc:", params.tcharacter)
          this.$axios.post(`/InsertTeacher`,params).then((res) => {
            console.log(res);
            if (res.data.msg=="插入教师成功") {
              alert("插入教师成功")
            } else {
              alert(res.data.msg)
            }
          });
          //alert('提交成功!');
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    Logout() {
      var _this = this;
      _this.$confirm('确认退出吗？', '提示', {}).then(() => {
        window.location.href = '/'
      }).catch(() => {})
    },
  }
}
</script>

<style scoped>

</style>
